#Const VERBOSE = True
Namespace Sql
  Public Class Access

#Region "Connection"
    Public Shared Function Connection(ByVal connectionString As String) As SqlConnection
      Dim rc As SqlConnection

      If connectionString Is Nothing OrElse connectionString.Length = 0 Then
        Throw New ArgumentException("The ConnectionString is not valid")
      Else
        rc = New SqlConnection(connectionString)
        rc.Open()
      End If
      Return rc
    End Function
#End Region

    '#Region "ExecuteReader"
    '    Private Shared Function ExecuteReader(ByVal query As String, ByVal connectionString As String) As SqlDataReader
    '      Dim cmd As SqlCommand
    '      Dim rc As SqlDataReader

    '#If VERBOSE Then
    '      Debug.WriteLine(String.Format("ExecuteReader(...){0}", Query))
    '#End If

    '      If (query Is Nothing) OrElse (query.Length = 0) Then
    '        Throw New ArgumentNullException("The query is empty")
    '      Else
    '        cmd = New SqlCommand(query, Connection(connectionString))
    '        rc = cmd.ExecuteReader()
    '        'cmd.Connection.Close()
    '        'cmd.Connection = Nothing
    '        Return rc
    '      End If
    '    End Function
    '#End Region

    '#Region "ExecuteDataSet"
    '    Private Shared Function ExecuteDataSet(ByVal Query As String, ByVal connectionString As String) As DataSet
    '      Dim da As SqlDataAdapter
    '      Dim rc As DataSet

    '#If VERBOSE Then
    '      Debug.WriteLine(String.Format("ExecuteDataSet(...){0}}", Query))
    '#End If

    '      If (Query Is Nothing) OrElse (Query.Length = 0) Then
    '        Throw New ArgumentNullException("The query is empty")
    '      Else
    '        da = New SqlDataAdapter(Query, connectionString)
    '        rc = New DataSet
    '        da.Fill(rc)
    '        Return rc
    '      End If
    '    End Function
    '#End Region

    '#Region "ExecuteDataTable"
    '    Private Shared Function ExecuteDataTable(ByVal Query As String, ByVal connectionString As String) As DataTable
    '      Dim da As SqlDataAdapter
    '      Dim rc As DataSet

    '#If VERBOSE Then
    '      Debug.WriteLine(String.Format("ExecuteDataTable(...){0}", Query))
    '#End If

    '      If (Query Is Nothing) OrElse (Query.Length = 0) Then
    '        Throw New ArgumentNullException("The query is empty")
    '      Else
    '        da = New SqlDataAdapter(Query, connectionString)
    '        rc = New DataSet
    '        da.Fill(rc)
    '      End If

    '      Return rc.Tables(0)
    '    End Function
    '#End Region

    '#Region "ExecuteScalar"
    '    Private Shared Function ExecuteScalar(ByVal Query As String, ByVal connectionString As String) As Object
    '      Dim cmd As SqlCommand
    '      Dim rc As Object = Nothing

    '#If VERBOSE Then
    '      Debug.WriteLine(String.Format("ExecuteScalar(...){0}", Query))
    '#End If

    '      If (Query Is Nothing) OrElse (Query.Length = 0) Then
    '        Throw New ArgumentNullException("The query is empty")
    '      Else
    '        cmd = New SqlCommand(Query, Connection(connectionString))
    '        'Try
    '        rc = cmd.ExecuteScalar()
    '        cmd.Connection = Nothing
    '        'Catch ex As Exception
    '        'MsgBox(ex.ToString())
    '        'End Try

    '        Return rc
    '      End If
    '    End Function
    '#End Region

    '#Region "ExecuteNonQuery"
    '    Private Shared Sub ExecuteNonQuery(ByVal Query As String, ByVal connectionString As String)
    '      Dim cmd As SqlCommand

    '#If VERBOSE Then
    '      Debug.WriteLine(String.Format("ExecuteNonQuery(...){0}", Query))
    '#End If

    '      If (Query Is Nothing) OrElse (Query.Length = 0) Then
    '        Throw New ArgumentNullException("The query is empty")
    '      Else
    '        cmd = New SqlCommand(Query, Connection(connectionString))
    '        cmd.ExecuteNonQuery()
    '        cmd.Connection = Nothing
    '      End If
    '    End Sub
    '#End Region
  End Class
End Namespace